package drinkkiosk.buttons;

import drinkkiosk.cards.SendCard;
import drinkkiosk.cards.UnlockCard;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;

/**NumberButton can be used to input any number into the TableNumber or Unlock 
 * Number displays.
 * @author Charles Ritchea
 */
public class NumberButton extends JButton implements ActionListener{
	/**The number to input*/
	private int digit;
	/**NumberButton() sets the number to 1
	 */
	public NumberButton() {
		super("1");
		digit = 1;
		setFont(new java.awt.Font("Arial", 0, 48));
		addActionListener(this);	
	}
	/**NumberButton(int digit) sets the number to whatever is passed
	 * @param digit int
	 */
	public NumberButton(int digit) {
		super(""+digit);
		this.digit = digit;
		setFont(new java.awt.Font("Arial", 0, 48));
		addActionListener(this);	
	}
	/**
	 * 
	 * @param e ActionEvent the event of pressing a NumberButton 
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		JButton button = (JButton)e.getSource();
		JPanel numberPanel = (JPanel)button.getParent();
		JLayeredPane layeredPane = (JLayeredPane)numberPanel.getParent();
		JPanel card = (JPanel)layeredPane.getParent();
		if(card instanceof SendCard){
			SendCard sendCard = (SendCard)card;
			sendCard.updateTableNumber(digit);
		} else if (card instanceof UnlockCard) {
			UnlockCard unlockCard = (UnlockCard)card;
			unlockCard.updateTableNumber(digit);
		}
		return;
	}
}